package top.blackr.folivora.common.pay.transfer;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import top.blackr.folivora.common.pay.exception.TransferException;
import top.blackr.folivora.common.pay.transfer.entity.TransferCallback;
import top.blackr.folivora.common.pay.transfer.entity.TransferRequest;

import java.util.Map;

/**
 * 提现工厂
 *
 * @author BlackR
 */
@Component
@AllArgsConstructor
public class TransferFactory {

    private final Map<String, ITransferStrategy<? extends TransferRequest, ?, ? extends TransferCallback>> transferStrategyMap;

    @SuppressWarnings("unchecked")
    public <R extends ITransferStrategy<?, ?, ?>> R getTransferStrategy(String transferType) {
        if (!transferStrategyMap.containsKey(transferType)) {
            throw new TransferException("暂不支持该提现方式，" + transferType);
        }
        return (R) transferStrategyMap.get(transferType);
    }
}
